<%@page import="java.awt.print.Printable"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>_${customer.customerName}_多件包装(及时打单)</title>
<script type="text/javascript">

  //注册快捷键
  $(document).keypress(function(e){ 
        if(e.altKey && (e.which==102 || e.which==70 ) ) {  
               pkg();
        }else if (e.altKey && (e.which==113 || e.which==81 ) ) { 
               queryOrder();
        }else if (e.altKey && (e.which==99 || e.which==67 ) ) { 
               reset();
        }else if(e.altKey && (e.which==117 || e.which==85 ) ) { 
           $("#btn_print_ebill").trigger("click");
        }else if(e.altKey && (e.which==112 || e.which==80 ) ) { 
           $("#print_ebill").trigger("click");
        } 

      
  });
 
  $(function() {
	  $("#txt_sku").focus();
  });
  
  var curOrderno;
  var taskCode="";//拣货任务号
  
  function reset(){
	  $("#txt_info").html('');
	  $("#txt_sku").focus();
	  $("#msg_sku").html("");
	  $("[name='exist']").hide();
      $("[name='noexist']").show();
  }
  
  //验证
  function queryOrder(){
	  var info=$("#txt_info").html().trim();
	   if(info==''){
	     $("#msg_sku").css("color","red");
	     $("#msg_sku").html("请扫描商品SKU编号!");
	     $("#txt_sku").focus();
		 return false;
	  }
	  
	  $.ajax({
			type:'post',
			url:'${ctx}/pkgTask/v2_ajaxCheckSkuInfo_multi',
			data:{
				skuInfo:info
			},
			dataType:'json',
			success:function(data) {
				var msg=data.msg;
				
				if(msg=='success'){
					$("#msg_sku").css("color","green");
					$("#msg_sku").html("订单匹配成功，请打印并包装...");
					$("#txt_sku").blur();
					taskCode=data.workOrder.taskCode;
					
					//显示订单信息
					var workOrder=data.workOrder;
				    showOrderInfo(workOrder);
				    curOrderno=workOrder.order.ordeno;
				    
				    //加载运单模板
				    var expressStyles=data.expressStyles;
				    var temp="";
				    $.each(expressStyles,function(i,obj){
				       temp+="<option value='"+obj.id+"'>"+obj.styleName+"</option>";
				    });
				    $("[name='expressStylesId']").html(temp);
				    
				    //加载随箱单模板
				    var packformStyles=data.packformStyles;
				    var _temp="";
				    $.each(packformStyles,function(i,obj){
				       _temp+="<option value='"+obj.id+"'>"+obj.styleName+"</option>";
				    });
				    $("#packformStylesId").html(_temp);
				    $("#packformStylesId").trigger("chosen:updated");
				    
				    $("#btn_print_ebill").trigger("click");
				    
				}else if(msg=='cancel'){
				    $("#msg_sku").css("color","red");
					$("#msg_sku").html("此单是取消单，请拦截勿包装！");
					
					//显示订单信息
					var workOrder=data.workOrder;
				    showOrderInfo(workOrder);
				    
				    
				    $("#btn_print_ebill").hide();
    	            $("#btn_print_cbill").hide();
    	            $("#btn_print_boxbill").hide();
    	            //$("#btn_pkg").hide();
    	            $("#txt_info").html("");
    	            
				    
				}else if(msg=='error'){
				    $("#msg_sku").css("color","red");
					$("#msg_sku").html("无匹配的订单待包装！");
					
					$("#txt_info").html('');
					$("#txt_sku").focus();
					$("[name='exist']").hide();
				    $("[name='noexist']").show();
				}
				else{
				    $("[name='exist']").hide();
                    $("[name='noexist']").show();
				}
				
				$("#txt_sku").focus();
				$("#txt_sku").val('');
				
			},
			error:function() {
				alert("网络繁忙，请稍后重试...");
			}
	   });
	  
  }
  
  //验证
  function change_sku(){
      $("#msg_sku").html("");
      
	  var sku=$("#txt_sku").val().trim();
	  if(sku==''){
		 return false;
	  }
	  
	  var info=$("#txt_info").html();
	  if(info.length>0){
		  info+=";";
	  }
	  info+=sku;
	  $("#txt_info").html(info);
	  
	  $("#txt_sku").focus();
	  $("#txt_sku").val('');
  }
  
  //显示商品信息
  function showOrderInfo(workOrder){
       $("[name='exist']").show();
       $("[name='noexist']").hide();
       
       $("#orderno").html(workOrder.order.ordeno);
       $("#expressNo").html(workOrder.expressNo);
       $("#expressName").html(workOrder.order.cacode);
       $("#address").html(workOrder.order.addres);
       $("#area").html(workOrder.order.provna+"/"+workOrder.order.cityna+"/"+workOrder.order.distna);
       $("#postco").html(workOrder.order.postco);
       $("#recena").html(workOrder.order.recena);
       $("#mobile").html(workOrder.order.mobile);
       $("#teleph").html(workOrder.order.teleph);
       
      // $("#btn_pkg").show();
       
       var orderType=workOrder.order.orderType;
       if(orderType=='single'){ 
    	   $("#orderType").html("单件");
       }else if(orderType=='multiple'){
    	   $("#orderType").html("多件");
       }
       
       var billType=workOrder.billType;
       if(billType=='cbill'){ 
    	   $("#billType").html("普通运单");
    	   $("#btn_print_ebill").hide();
    	   $("#btn_print_cbill").show();
    	   $("#btn_print_boxbill").show();
    	   
       }else if(billType=='ebill'){
    	   $("#billType").html("电子运单");
    	   $("#btn_print_ebill").show();
    	   $("#btn_print_cbill").hide();
    	   $("#btn_print_boxbill").hide();
       }
       
       var flowType=workOrder.flowType;
       if(flowType=='prePrint'){ 
    	   $("#flowType").html("预先打单");
       }else if(flowType=='intimePrint'){
    	   $("#flowType").html("即时打单");
       }
       
       var status=workOrder.status;
       if(status=='1'){ 
    	   $("#status").html("创建批次");
       }else if(status=='2'){
    	   $("#status").html("创建任务");
       }else if(status=='3'){
    	   $("#status").html("已拣货");
       }else if(status=='4'){
    	   $("#status").html("已灯光拣选");
       }else if(status=='5'){
    	   $("#status").html("已包装");
       }else if(status=='6'){
    	   $("#status").html("已发货");
       }else if(status=='7'){
    	   $("#status").html("已签收");
       }else if(status=='8'){
    	   $("#status").html("异常");
       }else if(status=='9'){
    	   $("#status").html("待包装");
       }
       
       //订单明细
       var str='';
       $.each(workOrder.order.orderItems,function(i,orderItem){
          str+="<tr name='exist'>";
          str+="<td>"+(i+1)+"</td>";
          str+="<td>"+orderItem.sku+"</td>";
          str+="<td>"+orderItem.qty+"</td>";
          str+="</tr>";
       });
       $("#orderItems").html(str);
  }
  
  //包装
  function pkg(){
      
    // var btn=$("#btn_pkg");
    // btn.attr("disabled",true);
    // btn.attr("class","btn");
  
	  $.ajax({
			type:'post',
			url:'${ctx}/pkgTask/ajaxPkg',
			data:{
				orderno:curOrderno
			},
			dataType:'json',
			success:function(data) {
				var msg=data.msg;
				if(msg=='success'){ 
				    $("#txt_info").html("");
					$("#txt_sku").focus();
					$("#msg_sku").css("color","green");
					$("#msg_sku").html("订单（"+curOrderno+"）包装完成");
					$("[name='exist']").hide();
                    $("[name='noexist']").show();
                    curOrderno='';
				}
				else if(msg='unprinted'){
				    alert("未打印，请打印快递单..");
				}
				else{
					alert("网络繁忙，请稍后重试...");
				}
				
				btn.attr("disabled",false);
                btn.attr("class","btn btn-primary");
				
				
			},
			error:function() {
				alert("网络繁忙，请稍后重试...");
				btn.attr("disabled",false);
                btn.attr("class","btn btn-primary");
			}
	   });
  }
  
  
</script>
</head>

<body>
<section class="content">
<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<h3 class="box-title">多件包装(即时打单)</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse" type="button">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
	<div class="box-body">
	<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
	    <tr>
		    <td style="width: 100px; font-weight: bold; vertical-align: middle;text-align: center;">SKU编号：</td>
		    <td colspan="9">
		    <div class="col-sm-3">
				<div class="input-textgroup col-sm-12">
				      <input type="text" class="form-control" id="txt_sku" onchange="change_sku();" style=""/>
				      <span style="color: red;font-weight: bold;" id="msg_sku"></span>
		   		</div>
		   	</div>
		    </td>
		</tr>
		
		 <tr>
		    <td style="width: 100px; font-weight: bold; vertical-align: middle;text-align: center;">扫描信息：</td>
		    <td colspan="9">
		    <div class="col-sm-3">
				<div class="input-textgroup col-sm-12">
			      <textarea  id="txt_info" class="form-control" style="margin-top: 10px;width: 800px;" readonly="readonly"></textarea>
			      <input type="button" id="btn_check" value="查询订单（alt+Q）"  class="btn btn-primary" onclick="queryOrder();" style="margin-top: 7px; margin-left: 10px;" />
			      <input type="button" value="清空（alt+C）"  class="btn btn-info" onclick="reset();" style="margin-top: 7px; margin-left: 10px;" />
		    	</div>
		    </div>
		    </td>
		</tr>
		
		<tr>
		    <td style="width: 100px; font-weight: bold; vertical-align: middle;text-align: center;">SKU编号：</td>
		    <td colspan="9" >
		      <span name="exist" style="display: none;">
		      <a id="btn_print_ebill" href="#printWorkBatchEbill" role="button" data-toggle="modal" class="btn btn-warning" onclick="changeStatus('ebill');" >打印电子运单（alt+U）</a>
		      <a id="btn_print_cbill" href="#printWorkBatchExpress" role="button" data-toggle="modal" class="btn btn-warning"   onclick="changeStatus('express');" >打印普通运单</a>
		      <a id="btn_print_boxbill" href="#printAllPackFormStyle" role="button" data-toggle="modal" class="btn btn-warning"   onclick="changeStatus('packForm');" >打印随箱单</a>
		      <input type="button" value="包装完成（alt+F）"   id="btn_pkg" class="btn btn-primary" onclick="pkg();" style="display: none;"/>
		      </span>
		    </td>
		</tr>
		
	</table>
	</div>
	</div>
	</div>
	</div>
	
	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<h3 class="box-title">运单信息</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse" type="button">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
	<div class="box-body">
	<!-- 运单信息 -->
	<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
		<tr name="noexist">
		     <td colspan="10" height="50"  style="vertical-align:middle; text-align: center;color: gray;font-size: 20px;">无数据</td>
		</tr>
		
		<thead name="exist" style="display: none;">
		    <th>订单编号</th>
			<th>运单编号</th>
			<th>快递公司</th>
			<th>省、市、区</th>
			<th>收货人</th>
			<th>联系手机</th>
			<th>联系座机</th>
			<th>收货人地址</th>
		</thead>
		
		<tr name="exist" style="display: none;">
		    <td id="orderno"></td>
		    <td id="expressNo"></td>
		    <td id="expressName"></td>
		    <td id="area"></td>
		    <td id="recena"></td>
		    <td id="mobile"></td>
		    <td id="teleph"></td>
		    <td id="address"></td>
		  </tr>
	</table>
	</div>
	</div></div></div>
	
	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<h3 class="box-title">订单详细信息</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse" type="button">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
	<div class="box-body">
	<!-- 订单详细信息 -->
	<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
		<tr name="noexist">
		     <td colspan="10" height="50"  style="vertical-align:middle; text-align: center;color: gray;font-size: 20px;">无数据</td>
		</tr>
		
		<thead name="exist" style="display: none;">
			<th>序号</th>
			<th>SKU</th>
			<th>数量</th>
		</thead>
		<tbody id="orderItems"></tbody>
	</table>
	</div></div>
	</div></div>
	<!-- 打印控件------------------------------------------------------------------------------------------------------------------------------------------------- -->

    <!-- 随箱单单 -->	
	<div style="display: none; width: 500px" class="modal hide fade"
			tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
			aria-hidden="true" id="printAllPackFormStyle">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">
					×
				</button>
				<h3 id="myModalLabel">
					打印随箱单信息
				</h3>
				<span id="messageLable"></span>
			</div>
			<div class="modal-body">
				<div class="control-group">
					<div class="controls">
						选择打印机:
						<select id="packFormStylePrint" name="packFormPrinter" style="width: 300px"></select>
					</div>
				</div>
				<div class="control-group">
					<div class="controls">
						选择随箱单:
						<select id="packformStylesId" name="packformStyleId" style="width: 300px" onchange="getAjaxPackformStyle();">
<!-- 							<c:forEach items="${packformStyles}" var="obj"> -->
<!-- 								<option value="${obj.id}">${obj.styleName}</option> -->
<!-- 							</c:forEach> -->
						</select>
					</div>
				</div>
			</div>

			<div class="modal-footer">
				<a class="btn btn-primary" data-dismiss="modal" aria-hidden="true"
					onclick="pageAjaxPrinter(this)"> 立即打印 </a>
				<a class="btn" data-dismiss="modal" aria-hidden="true"> 关闭（esc） </a>
			</div>
		</div>


<!-- 电子运单 -->
<div style="display: none; width: 500px" class="modal hide fade"
			tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
			aria-hidden="true" id="printWorkBatchEbill">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true"> × </button>
				<h3 id="expressLabel"> 打印电子面单信息 </h3>
				<span id="messageLable"></span>
			</div>
			<div class="modal-body">
				<div class="control-group">
					<div class="controls">
						选择打印机:
						<select id="ebillPrint" name="packFormPrinter" style="width: 300px"> </select>
					</div>
				</div>
				<div class="control-group">
					<div class="controls">
						选择快递单:
						<select id="expressStylesId" name="expressStylesId" style="width: 300px" onchange="getAjaxExpress();"></select>
					</div>
				</div>
			</div>

			<div class="modal-footer">
				<a class="btn btn-primary" data-dismiss="modal" aria-hidden="true" id="print_ebill"  onclick="pageAjaxPrinter(this)"> 立即打印 （alt+P）</a>
				<a class="btn" data-dismiss="modal" aria-hidden="true"> 关闭 （esc）</a>
			</div>
		</div>

		<div style="display: none; width: 500px" class="modal hide fade"
			tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
			aria-hidden="true" id="printWorkBatchExpress">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">
					×
				</button>
				<h3 id="expressLabel">
					打印快递单单信息
				</h3>
				<span id="messageLable"></span>
			</div>
			<div class="modal-body">
				<div class="control-group">
					<div class="controls">
						选择打印机:
						<select id="expressPrint" name="packFormPrinter"
							style="width: 300px">

						</select>
					</div>
				</div>
				<div class="control-group">
					<div class="controls">
						选择快递单:
						<select id="expressStylesId" name="expressStylesId" style="width: 300px" onchange="getAjaxExpress();"></select>
					</div>
				</div>
				<div>
					起始运单号:
					<input type="text" id="firstExpressNumber" style="width: 290px;" />
				</div>
			</div>

			<div class="modal-footer">
				<a class="btn btn-primary" data-dismiss="modal" aria-hidden="true"
					onclick="pageAjaxPrinter(this)"> 立即打印 </a>
				<a class="btn" data-dismiss="modal" aria-hidden="true"> 关闭 </a>
			</div>
		</div>
</section>	
<!-- ------------------------------------------------------------------------------------------------------------------------------------------------------- -->




<script type="text/javascript">
var LODOP; //声明为全局变量 
var expressRex="";//运单号正则表达式
var packformName="";
var printName="";//打印机名称
var status="";
var focusItem=null;

function changeStatus(item){
	
	$("#firstExpressNumber").val('');
	$("#btn_print_ebill").blur();
	
	status=item;
	if("packForm"==item){
		 packFormPrinter("packFormStylePrint");
	}else if("express"==item){
		 packFormPrinter("expressPrint");
	}else if("ebill"==item){
		 packFormPrinter("ebillPrint");
		 
		 //设置默认打印机，相同于上次打印选择.
		 if(printName==''){
		 }else{
		   $("#ebillPrint").val(printName)
		 }
	}
}

function printExpress(taskName,printerName,content,width,height,rankno,expressNo) {
	LODOP.PRINT_INIT(taskName);
	LODOP.SET_PRINT_PAGESIZE(1,width,height,""); 
	LODOP.ADD_PRINT_TEXT(20,20,300,20,rankno);
	LODOP.ADD_PRINT_BARCODE(10, 200, 180, 40, "128B", expressNo);
	eval(content);
	if (LODOP.SET_PRINTER_INDEXA(printerName)) {
		LODOP.PRINT();
	}
}

function verify(content) {
	var result =content.match(expressRex);
	if(result==null){
	  return false;
	}
	return true;
}


function initLodop() {
	LODOP = getLodop(document.getElementById('LODOP_OB'), document
			.getElementById('LODOP_EM'));
}



function getBodyContentString(content) {
	content = content.replace(/<[^>]*?>(.*?)/gi, '='); //删除左部
	content = content.replace(/(.*?)<\/[^>]*?>/gi, '='); //删除右部
	var bodyContents = content.split("=");
	return bodyContents;
}


//整除
function Div(exp1, exp2){
	var n1 = Math.round(exp1); //四舍五入
	var n2 = Math.round(exp2); //四舍五入
	var rslt = n1 / n2; //除
	if (rslt >= 0){
	    rslt = Math.floor(rslt); //返回值为小于等于其数值参数的最大整数值。
	}else {
	    rslt = Math.ceil(rslt); //返回值为大于等于其数字参数的最小整数。
	}
	return rslt;
}


function pageAjaxPrinter(item){
   $(item).attr("disabled",true);
   focusItem=item;
   if("express"==status){
        var firstExpressNumber = $("#firstExpressNumber").val();//运单号
	    var expressStylesId = $("#expressStylesId").val();//快递单样式
	
	    printName=$("#expressPrint").val();
        if(!verify(firstExpressNumber)){
           alert("请输入正确的订单号！");
           return;
        }
       ajaxPrintPackExpressOrdenos(curOrderno,firstExpressNumber,expressStylesId);
   }else if("packForm"==status){
	   printName= $("#packFormStylePrint").val();
   	   var packformStylesId = $("#packformStylesId").val();//随箱单样式
       ajaxPrintPackFormOrdenos(curOrderno,packformStylesId);
   }else if("ebill"==status){
	   printName= $("#ebillPrint").val();
	   var expressStylesId = $("#expressStylesId").val();//快递单样式
	   ajaxPrintEBillExpress(curOrderno,expressStylesId);
   }

}


function ajaxPrintPackFormOrdenos(ordenos,packformStyleId){
showBg();
$.ajax({
		type : 'post',
		url : '${ctx}/print/ajaxPrintPackFormOrdenos',
		data : 'ordenos=' + ordenos+'&packformStyleId='+packformStyleId,
		dataType : 'json',
		success : function(data) {
			 if (data.status == "1") {
				initLodop();
				$.each(data.content, function(i) {
					 printStyle(packformName,data.content[i].taskName,printName,data.content[i].content,data.content[i].ordeno,data.content[i].expressNo,data.content[i].taskName);
				});
				 $(focusItem).attr("disabled",false);
			    $("#message").html("<span class=\"label label-success\">打印机加载完毕</span>");
			      closeBg();
			} else if (data.status == "-3") {
		    	closeBg();
				alert("请输入正确的运单号！");
			} else if (data.status == "0") {
			    closeBg();
				alert("加载错误！");
			}

		},

		error : function() {
            alert("服务器异常");
		}
	});
}

function ajaxPrintEBillExpress(ordenos,expressId){
	  showBg();
	$.ajax({
			type : 'post',
			url : '${ctx}/print/ajaxPrintEBillExpress',
			data : 'ordenos=' + ordenos+'&expressId='+expressId+'&taskCode='+taskCode,
			dataType : 'json',
			success : function(data) {
				 if (data.status == "1") {
					initLodop();
					$.each(data.content, function(i) {
						
						    var str=data.content[i].content;
						    str=str.replace(/\r\n/g,"");
						    if(data.openCaiNiao == "1"){
						    	printMailExpressByURL(data.content[i].taskName,printName,str,data.width,data.height,data.content[i],data.expressStyle,taskCode);
						    }else{
						    	printMailExpress(data.content[i].taskName,printName,str,data.width,data.height,data.content[i].expressNo);
						    }
						    
						    
						
					});
					 $(focusItem).attr("disabled",false);
				    $("#message").html("<span class=\"label label-success\">打印机加载完毕</span>");
				       closeBg();
				       pkg();
				} else if (data.status == "-3") {
			    	closeBg();
					alert("请输入正确的运单号！");
				} else if (data.status == "0") {
				    closeBg();
					alert("加载错误！");
				}

			},

			error : function() {

			}
		});
	}
//通过URL打印电子面单
function printMailExpressByURL(taskName,printName,content,width,height,printerStyleType,expressStyle,taskCode){
	 	var adjustTop = 0;
	 	var adjustLeft = 0;
		var companyCode = expressStyle.logisticsCompany.companyCode;
		LODOP.PRINT_INIT(taskName);
		//LODOP.ADD_PRINT_TEXT(10, 10, 200, 20, rankno);
		LODOP.SET_PRINT_PAGESIZE(1,width,height,""); 
		LODOP.SET_SHOW_MODE("MESSAGE_GETING_URL",""); //该语句隐藏进度条或修改提示信息
		LODOP.SET_SHOW_MODE("MESSAGE_PARSING_URL","");//该语句隐藏进度条或修改提示信息
		LODOP.ADD_PRINT_URL(adjustTop, adjustLeft, "100%", "100%", expressStyle.styleContent+"?ordeno="+printerStyleType.ordeno+"&taskCode="+taskCode+"&cpCode="+companyCode);
		if("YTO" == companyCode){
			LODOP.ADD_PRINT_BARCODE((38+adjustTop)+"mm", (30+adjustLeft)+"mm", "45mm", "13mm", expressStyle.barCode, printerStyleType.expressNo);
			LODOP.ADD_PRINT_BARCODE((106+adjustTop)+"mm", (52+adjustLeft)+"mm", "45mm", "13mm", expressStyle.barCode, printerStyleType.expressNo);			
		}
		else if("STO" == companyCode){
			LODOP.ADD_PRINT_BARCODE((70+adjustTop)+"mm", (20+adjustLeft)+"mm", "40mm", "13mm", expressStyle.barCode, printerStyleType.expressNo);
			LODOP.ADD_PRINT_BARCODE((165+adjustTop)+"mm", (10+adjustLeft)+"mm", "40mm", "13mm", expressStyle.barCode, printerStyleType.expressNo);
			LODOP.ADD_PRINT_BARCODE((133+adjustTop)+"mm", (15+adjustLeft)+"mm", "40mm", "25", expressStyle.barCode, printerStyleType.fromno);
		}
		else if("GTO" == companyCode){
			LODOP.ADD_PRINT_BARCODE((70+adjustTop)+"mm", (20+adjustLeft)+"mm", "40mm", "13mm", expressStyle.barCode, printerStyleType.expressNo);
			LODOP.ADD_PRINT_BARCODE((165+adjustTop)+"mm", (10+adjustLeft)+"mm", "40mm", "13mm", expressStyle.barCode, printerStyleType.expressNo);
			LODOP.ADD_PRINT_BARCODE((133+adjustTop)+"mm", (15+adjustLeft)+"mm", "40mm", "25", expressStyle.barCode, printerStyleType.fromno);
		}
		else if("QFKD" == companyCode){
			LODOP.ADD_PRINT_BARCODE((70+adjustTop)+"mm", (20+adjustLeft)+"mm", "40mm", "13mm", expressStyle.barCode, printerStyleType.expressNo);
			LODOP.ADD_PRINT_BARCODE((165+adjustTop)+"mm", (10+adjustLeft)+"mm", "40mm", "13mm", expressStyle.barCode, printerStyleType.expressNo);
			LODOP.ADD_PRINT_BARCODE((133+adjustTop)+"mm", (15+adjustLeft)+"mm", "40mm", "25", expressStyle.barCode, printerStyleType.fromno);
		}
		else if("TTKDEX" == companyCode){
			LODOP.ADD_PRINT_BARCODE((70+adjustTop)+"mm", (20+adjustLeft)+"mm", "40mm", "13mm", expressStyle.barCode, printerStyleType.expressNo);
			LODOP.ADD_PRINT_BARCODE((165+adjustTop)+"mm", (10+adjustLeft)+"mm", "40mm", "13mm", expressStyle.barCode, printerStyleType.expressNo);
			LODOP.ADD_PRINT_BARCODE((133+adjustTop)+"mm", (15+adjustLeft)+"mm", "40mm", "25", expressStyle.barCode, printerStyleType.fromno);
		}
		else if("FAST" == companyCode){
			LODOP.ADD_PRINT_BARCODE((70+adjustTop)+"mm", (20+adjustLeft)+"mm", "40mm", "13mm", expressStyle.barCode, printerStyleType.expressNo);
			LODOP.ADD_PRINT_BARCODE((165+adjustTop)+"mm", (10+adjustLeft)+"mm", "40mm", "13mm", expressStyle.barCode, printerStyleType.expressNo);
			LODOP.ADD_PRINT_BARCODE((133+adjustTop)+"mm", (15+adjustLeft)+"mm", "40mm", "25", expressStyle.barCode, printerStyleType.fromno);
		}
		else if("SF" == companyCode){
			LODOP.ADD_PRINT_BARCODE((50+adjustTop)+"mm", (15+adjustLeft)+"mm", "40mm", "13mm", expressStyle.barCode, printerStyleType.expressNo);
			LODOP.ADD_PRINT_BARCODE((103+adjustTop)+"mm", (15+adjustLeft)+"mm", "40mm", "13mm", expressStyle.barCode, printerStyleType.expressNo);
			LODOP.ADD_PRINT_BARCODE((133+adjustTop)+"mm", (15+adjustLeft)+"mm", "40mm", "25", "128A", printerStyleType.fromno);
		}
		else if("ZTO" == companyCode){
			LODOP.ADD_PRINT_BARCODE((80+adjustTop)+"mm", (15+adjustLeft)+"mm", "70mm", "13mm", expressStyle.barCode, printerStyleType.expressNo);
			LODOP.ADD_PRINT_BARCODE((105+adjustTop)+"mm", (40+adjustLeft)+"mm", "60mm", "13mm", expressStyle.barCode, printerStyleType.expressNo);
		}
		else if("POSTB" == companyCode){
			LODOP.ADD_PRINT_BARCODE((3+adjustTop)+"mm", (40+adjustLeft)+"mm", "50mm", "13mm", expressStyle.barCode, printerStyleType.expressNo);
			LODOP.ADD_PRINT_BARCODE((93+adjustTop)+"mm", (3+adjustLeft)+"mm", "50mm", "13mm", expressStyle.barCode, printerStyleType.expressNo);
		}
		else if("YUNDA" == companyCode){
			LODOP.ADD_PRINT_BARCODE((64+adjustTop)+"mm", (25+adjustLeft)+"mm", "60mm", "17mm", expressStyle.barCode, printerStyleType.expressNo);
			LODOP.SET_PRINT_STYLEA(0,"ShowBarText",0);
			LODOP.ADD_PRINT_BARCODE((153+adjustTop)+"mm", (25+adjustLeft)+"mm", "60mm", "10mm", expressStyle.barCode, printerStyleType.expressNo);
			LODOP.SET_PRINT_STYLEA(0,"ShowBarText",0);
		}
		else{
			LODOP.ADD_PRINT_BARCODE(27,43,220,40,"",printerStyleType.expressNo);
		}
		
		//LODOP.SET_SHOW_MODE("BKIMG_PRINT", 1);
		//LODOP.PREVIEW();
		if (LODOP.SET_PRINTER_INDEXA(printName)) {
			LODOP.PRINT();
		}
	}
function printMailExpress(taskName,printName,content,width,height,expressNo){
	LODOP.PRINT_INIT(taskName);
	//LODOP.ADD_PRINT_TEXT(10, 10, 200, 20, rankno);
	LODOP.SET_PRINT_PAGESIZE(1,width,height,""); 
	var strCenterStyle = "<style/>table {width:100%}</style>";
	LODOP.ADD_PRINT_HTM(-10, 12, "100%", "100%", strCenterStyle + content);
	LODOP.ADD_PRINT_BARCODE(27,43,220,40,"",expressNo);
	//LODOP.SET_SHOW_MODE("BKIMG_PRINT", 1);
	//LODOP.PREVIEW();
	if (LODOP.SET_PRINTER_INDEXA(printName)) {
		LODOP.PRINT();
	}
	
}

function ajaxPrintPackExpressOrdenos(ordenos,firstExpress,expressId){
  showBg();
$.ajax({
		type : 'post',
		url : '${ctx}/print/ajaxPrintPackExpressOrdenos',
		data : 'ordenos=' + ordenos+'&firstExpress='+firstExpress+'&expressId='+expressId,
		dataType : 'json',
		success : function(data) {
			 if (data.status == "1") {
				initLodop();
				$.each(data.content, function(i) {
					
					    var str=data.content[i].content;
					    str=str.replace(/\r\n/g,"");
					printExpress(data.content[i].taskName,printName,str,data.width,data.height,data.content[i].taskName,data.content[i].expressNo);
					
				});
				 $(focusItem).attr("disabled",false);
			    $("#message").html("<span class=\"label label-success\">打印机加载完毕</span>");
			       closeBg();
			} else if (data.status == "-3") {
		    	closeBg();
				alert("请输入正确的运单号！");
			} else if (data.status == "0") {
			    closeBg();
				alert("加载错误！");
			}

		},

		error : function() {

		}
	});
}

function printStyle(indentfy,taskName, printerName, printContent,ordeno, expressNo,rankno){
  if("OSA-A5"==indentfy){
     printFivePackStyle(taskName,printerName,printContent,ordeno,expressNo,rankno);
  }else if("OSA-A4"==indentfy){
     printFourPackStyle(taskName,printerName,printContent,ordeno,expressNo,rankno);
  }else if("RY1_A5"==indentfy){
     printFivePackStyleRy(taskName,printerName,printContent,ordeno,expressNo,rankno);
  }else if("9love_A5"==indentfy){
     printFivePackStyleLove(taskName,printerName,printContent,ordeno,expressNo,rankno);
  }else if("HS1-A5"==indentfy){
	 printFivePackStyleHS1(taskName, printerName, printContent, ordeno,expressNo,rankno);
  }else{
     printFivePackStyle(taskName,printerName,printContent,ordeno,expressNo,rankno);
  }

}

function printFivePackStyleHS1(taskName, printerName, printContent, ordeno,expressNo,
		rankno) {
	LODOP.PRINT_INIT(taskName);
	LODOP.ADD_PRINT_TEXT(10, 10, 200, 20, rankno);

	var strCenterStyle = "<style/>table {width:100%}</style>";
	LODOP.ADD_PRINT_HTM(30, 0, "100%", "100%", strCenterStyle
			+ printContent);
	LODOP.ADD_PRINT_BARCODE(10, 50, 380, 40, "128B", ordeno);
	LODOP.ADD_PRINT_BARCODE(650, 280, 200, 20, "128B", expressNo);
	if (LODOP.SET_PRINTER_INDEXA(printerName)) {
		LODOP.PRINT();
	}
}

function printFivePackStyleLove(taskName, printerName, printContent,oraden, expressNo,rankno) {
	LODOP.PRINT_INIT(taskName);
	LODOP.ADD_PRINT_TEXT(20,20,300,10,rankno);
	
	LODOP.ADD_PRINT_BARCODE(40, 20, 180, 40, "128B", oraden);
	LODOP.ADD_PRINT_BARCODE(40, 250, 180, 40, "128B", expressNo);
	var strCenterStyle = "<style/>table {width:100%}</style>";
	LODOP.ADD_PRINT_HTM(80, 0, "100%", "100%", strCenterStyle
			+ printContent);
	if (LODOP.SET_PRINTER_INDEXA(printerName)) {
		LODOP.PRINT();
	}
}

function printFivePackStyleRy(taskName, printerName, printContent,ordeno, expressNo,rankno) {
	LODOP.PRINT_INIT(taskName);
	LODOP.ADD_PRINT_TEXT(20,20,300,10,rankno);

	var strCenterStyle = "<style/>table {width:100%}</style>";
	LODOP.ADD_PRINT_HTM(80, 0, "100%", "100%", strCenterStyle
			+ printContent);
    LODOP.ADD_PRINT_BARCODE(40, 10, 180, 40, "128B", ordeno);
	LODOP.ADD_PRINT_BARCODE(40, 250, 180, 40, "128B", expressNo);
	if (LODOP.SET_PRINTER_INDEXA(printerName)) {
		LODOP.PRINT();
	}
}

function printFivePackStyle(taskName, printerName, printContent,ordeno, expressNo,rankno) {
	LODOP.PRINT_INIT(taskName);
	LODOP.ADD_PRINT_TEXT(20,20,300,10,rankno);

	var strCenterStyle = "<style/>table {width:100%}</style>";
	LODOP.ADD_PRINT_HTM(215, 0, "100%", "100%", strCenterStyle
			+ printContent);
    LODOP.ADD_PRINT_BARCODE(200, 100, 350, 40, "128B", ordeno);
	LODOP.ADD_PRINT_BARCODE(650, 280, 200, 20, "128B", expressNo);
	if (LODOP.SET_PRINTER_INDEXA(printerName)) {
		LODOP.PRINT();
	}
}

function printFourPackStyle(taskName, printerName, printContent,oraden, expressNo,rankno) {
	LODOP.PRINT_INIT(taskName);
	LODOP.ADD_PRINT_TEXT(20,20,300,10,rankno);
	
	LODOP.ADD_PRINT_BARCODE(40, 200, 300, 50, "128B", oraden);
	LODOP.ADD_PRINT_BARCODE(40, 830, 200, 40, "128B", expressNo);
	var strCenterStyle = "<style/>table {width:100%}</style>";
	LODOP.ADD_PRINT_HTM(80, 0, "100%", "100%", strCenterStyle
			+ printContent);
	if (LODOP.SET_PRINTER_INDEXA(printerName)) {
		LODOP.PRINT();
	}
}

function getAjaxExpress() {
    var expressStylesId = $("#expressStylesId").val();
		$.ajax({
			type : 'post',
			url : '${ctx}/v2/packformStyle/getAjaxExpress',
			data : 'expressStylesId=' + expressStylesId,
			dataType : 'json',
			success : function(data) {
				if (data.status == "1") {
					expressRex=data.content.logisticsCompany.regMailNo;
				}  else if (data.status == "0") {
					alert("获取运单号正则表达式错误！");
				}
			},

			error : function() {

			}
		});
	}
	
	
	
	function getAjaxPackformStyle() {
		var packformStylesId = $("#packformStylesId").val();
		if (packformStylesId == "" || packformStylesId == null) {
			alert("还没有这个随箱单");
			return;
		}
		$.ajax({
			type : 'post',
			url : '${ctx}/v2/packformStyle/getAjaxPackformStyle',
			data : 'packformStylesId=' + $("#packformStylesId").val(),
			dataType : 'json',
			success : function(data) {
				if (data.status == "1") {

					packformName = data.name;
					//packStyleType = data.type;
				
				} else if (data.status == "0") {
					alert("获取随箱单信息错误！");
				}

			},
			error : function() {
				alert("服务器异常");
			}
		});
	}

</script>
</body>
</html>
